package me.zhengjie.modules.management.rest.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.management.domain.ConferenceRecord;
import me.zhengjie.modules.management.domain.ConferenceRoom;
import me.zhengjie.modules.management.domain.Pageable;
import me.zhengjie.modules.management.service.ConferenceRecordService;
import me.zhengjie.modules.management.service.ConferenceRoomService;
import me.zhengjie.modules.management.service.dto.*;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Date;

/**
 * @Author: yuchao.wang
 * @Date: 2020/12/15
 * @Description: 预约列表主表
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "MR:预约列表主表")
@RequestMapping("/api/conferenceRecord")
public class ConferenceRecordController {

    private final ConferenceRecordService conferenceRecordService;

    @GetMapping
    @Log("获取预约信息")
    @ApiOperation("获取预约信息")
    public Object getAllList(ConferenceRecordQueryCriteria conferenceRecordQueryCriteria, Pageable pageable){
        return  conferenceRecordService.searchRecord(conferenceRecordQueryCriteria,pageable);
    }


    @GetMapping("/list")
    @Log("获取预约报表")
    @ApiOperation("获取预约报表")
    public Object queryByCriteria(ConferenceRecordQueryCriteria conferenceRecordQueryCriteria, Pageable pageable){
        return  conferenceRecordService.queryByCriteria(conferenceRecordQueryCriteria,pageable);
    }

    @PostMapping
    @Log("新增预约信息")
    @ApiOperation("新增预约信息")
    public void addConferenceRecord(@RequestBody RecordDto recordDto){


        recordDto.setCreateUserId(SecurityUtils.getCurrentUsername());
        recordDto.setCreateDateTime(new Timestamp(new Date().getTime()));
        conferenceRecordService.create(recordDto);
    }

    @PutMapping
    @Log("修改会议室信息")
    @ApiOperation("修改会议室信息")
    public void updateConferenceType (@RequestBody ConferenceRecordDto conferenceRecordDto) {
        conferenceRecordDto.setModifyUserId(SecurityUtils.getCurrentUsername());
        conferenceRecordDto.setModifyDateTime(new Timestamp(new Date().getTime()));
        conferenceRecordService.update(conferenceRecordDto);
    }

    @GetMapping(value = "/find")
    @Log("根据ID查询具体预约信息")
    @ApiOperation("根据ID查询具体预约信息")
    public Object getById(Integer recordId) {
        return conferenceRecordService.findById(recordId);
    }

    @GetMapping(value = "/time")
    @Log("根据ID查询预约有效时间")
    @ApiOperation("根据ID查询预约有效时间")
    public Object getTime(Integer recordId) {
        return conferenceRecordService.getTime(recordId);
    }

    @GetMapping(value = "/NotExpired")
    @Log("查询当天未过期的会议记录")
    @ApiOperation("查询当天未过期的会议记录")
    public Object getNotExpiredRecord() {
        return conferenceRecordService.findNotExpiredRecord();
    }

    /*@DeleteMapping
    @Log("删除预约信息")
    @ApiOperation("删除预约信息")
    public void deleteReocrd(@RequestBody RecordDto recordDto){
       conferenceRecordService.deleteRecord(recordDto);
    }*/

    @PutMapping(value = "/cancel")
    @Log("取消预约信息")
    @ApiOperation("取消预约信息")
    public void cancelReocrd(@RequestBody RecordDto recordDto){
        conferenceRecordService.cancelRecord(recordDto);
    }


}

